using System;
using System.Collections;
using System.Runtime.InteropServices;
namespace BMC.ARSystem
{
	[ClassInterface, ComVisible(false), Guid("556df2fe-69a0-400a-b908-c38cdeb52bf0"), ProgId("BMC.ARSystem.SetFieldsAction")]
	public abstract class SetFieldsAction : Action
	{
		private ArrayList _fieldAssignments;
		[ARStructMemTypeInfo(Name = "sampleServer", Offset = 1u)]
		private string _sampleServer;
		[ARStructMemTypeInfo(Name = "sampleForm", Offset = 2u)]
		private string _sampleForm;
		private string _fromServer;
		private string _readValuesFrom;
		private bool _byLikeIds;
		private bool _isSetToDefaults;
		public string FromServer
		{
			get
			{
				return this._fromServer;
			}
			set
			{
				this._fromServer = value;
			}
		}
		public string ReadValuesFrom
		{
			get
			{
				return this._readValuesFrom;
			}
			set
			{
				this._readValuesFrom = value;
			}
		}
		public string SampleServer
		{
			get
			{
				return this._sampleServer;
			}
			set
			{
				this._sampleServer = value;
			}
		}
		public string SampleForm
		{
			get
			{
				return this._sampleForm;
			}
			set
			{
				this._sampleForm = value;
			}
		}
		public ArrayList FieldAssignments
		{
			get
			{
				return this._fieldAssignments;
			}
			set
			{
				this._fieldAssignments = value;
			}
		}
		public bool IsAssignmentsByMatchingIds
		{
			get
			{
				return this._byLikeIds;
			}
			set
			{
				if (this._byLikeIds == value)
				{
					return;
				}
				this.FieldAssignments = new ArrayList();
				this._byLikeIds = value;
			}
		}
		public bool IsAssignmentSetToDefaults
		{
			get
			{
				return this._isSetToDefaults;
			}
			set
			{
				if (this._isSetToDefaults == value)
				{
					return;
				}
				this.FieldAssignments = new ArrayList();
				this._isSetToDefaults = value;
			}
		}
		public SetFieldsAction()
		{
		}
		protected SetFieldsAction(object[] rawData, Server server)
		{
			this.FromServer = server.Session.SecondaryServerName;
			this.SampleServer = (string)Util.GetAt(rawData, new int[]
			{
				1
			});
			if (server.Session.SecondaryServerName != null && server.Session.SecondaryServerName.StartsWith("$") && server.Session.SecondaryServerName.EndsWith("$"))
			{
				server.Session.SecondaryServerName = this.SampleServer;
			}
			else
			{
				if (server.Session.SecondaryServerName != null && (server.Session.SecondaryServerName.Equals("@") || server.Session.SecondaryServerName.EndsWith("*")))
				{
					server.Session.SecondaryServerName = server.Session.PrimaryServerName;
				}
			}
			this.SampleForm = (string)Util.GetAt(rawData, new int[]
			{
				2
			});
			if (server.Session.CurrentRemoteForm.StartsWith("$") && server.Session.CurrentRemoteForm.EndsWith("$"))
			{
				server.Session.CurrentRemoteForm = this.SampleForm;
			}
			if (server.Session.CurrentRemoteForm != null && (server.Session.CurrentRemoteForm.Equals("@") || server.Session.CurrentRemoteForm.Equals("*") || server.Session.CurrentRemoteForm.Equals("CURRENT SCREEN") || server.Session.CurrentRemoteForm.Equals("CURRENT TRANSACTION")))
			{
				server.Session.CurrentRemoteForm = server.Session.CurrentLocalForm;
			}
			int[] indexSpec = new int[1];
			this.FieldAssignments = Util.BuildFieldAssignmentList(Util.GetAt(rawData, indexSpec), server.Session.GetServer(server.Session.SecondaryServerName), server.Session.CurrentLocalForm, server.Session.CurrentRemoteForm, out this._byLikeIds, out this._isSetToDefaults);
		}
		internal static SetFieldsAction createInstance(object[] rawData, Server server)
		{
			string arg_1C_0 = "ARFieldAssignList";
			int[] array = new int[1];
			object[] firstARAssignFieldStruct = SetFieldsAction.GetFirstARAssignFieldStruct(arg_1C_0, (object[])Util.GetAt(rawData, array));
			uint arg_3D_0;
			if (firstARAssignFieldStruct != null)
			{
				object arg_30_0 = firstARAssignFieldStruct;
				array = new int[1];
				arg_3D_0 = Convert.ToUInt32(Util.GetAt(arg_30_0, array));
			}
			else
			{
				arg_3D_0 = 0u;
			}
			SetFieldsAction setFieldsAction;
			switch (arg_3D_0)
			{
			case 1:
			case 2:
			case 4:
			case 5:
			{
				object arg_8E_0 = firstARAssignFieldStruct;
				array = new int[2];
				array[0] = 1;
				string text = (string)Util.GetAt(arg_8E_0, array);
				string text2 = (string)Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					1
				});
				if (text != "*" && text != "@" && text != server.ServerName)
				{
					server = server.Session.GetServer(text);
				}
				if (text2 == "*" || text2 == "@")
				{
					setFieldsAction = new SetFieldsFromCurrent(rawData, server);
					return setFieldsAction;
				}
				server.Session.SecondaryServerName = text;
				server.Session.CurrentRemoteForm = text2;
				SetFieldsFromForm setFieldsFromForm = new SetFieldsFromForm(rawData, server);
				if (server.Session.CurrentRemoteForm.StartsWith("$") && server.Session.CurrentRemoteForm.EndsWith("$"))
				{
					server.Session.CurrentRemoteForm = setFieldsFromForm.SampleForm;
				}
				if (server.Session.CurrentRemoteForm != null && (server.Session.CurrentRemoteForm.Equals("@") || server.Session.CurrentRemoteForm.Equals("*") || server.Session.CurrentRemoteForm.Equals("CURRENT SCREEN") || server.Session.CurrentRemoteForm.Equals("CURRENT TRANSACTION")))
				{
					server.Session.CurrentRemoteForm = server.Session.CurrentLocalForm;
				}
				setFieldsFromForm.SetIfQualification = server.FormatSetIfQualification(server.Session.CurrentRemoteForm, server.Session.CurrentLocalForm, Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					2
				}));
				setFieldsFromForm.NoMatchOption = (uint)Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					5
				});
				setFieldsFromForm.MultiMatchOption = (uint)Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					6
				});
				setFieldsAction = setFieldsFromForm;
				setFieldsAction.FromServer = text;
				setFieldsAction.ReadValuesFrom = text2;
				return setFieldsAction;
			}
			case 7:
			{
				SetFieldsFromSQL setFieldsFromSQL = new SetFieldsFromSQL(rawData, server);
				SetFieldsAction arg_2C1_0 = setFieldsFromSQL;
				object arg_2B7_0 = firstARAssignFieldStruct;
				array = new int[2];
				array[0] = 1;
				arg_2C1_0.FromServer = (string)Util.GetAt(arg_2B7_0, array);
				setFieldsFromSQL.ReadValuesFrom = "SQL";
				setFieldsFromSQL.SqlCommand = (string)Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					1
				});
				setFieldsFromSQL.NoMatchOption = (uint)Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					3
				});
				setFieldsFromSQL.MultiMatchOption = (uint)Util.GetAt(firstARAssignFieldStruct, new int[]
				{
					1,
					4
				});
				setFieldsAction = setFieldsFromSQL;
				return setFieldsAction;
			}
			case 8:
				setFieldsAction = new SetFieldsFromFilterAPI(rawData, server);
				return setFieldsAction;
			}
			setFieldsAction = new SetFieldsFromCurrent(rawData, server);
			return setFieldsAction;
		}
		internal static object ToVariant(object given, Server server)
		{
			SetFieldsAction setFieldsAction = given as SetFieldsAction;
			if (setFieldsAction == null)
			{
				return given;
			}
			object[] array = new object[3];
			server.Session.PrimaryServerName = server.ServerName;
			server.Session.SecondaryServerName = setFieldsAction.FromServer;
			if (server.Session.SecondaryServerName != null && server.Session.SecondaryServerName.StartsWith("$") && server.Session.SecondaryServerName.EndsWith("$"))
			{
				server.Session.SecondaryServerName = setFieldsAction.SampleServer;
			}
			if (server.Session.SecondaryServerName != null && (server.Session.SecondaryServerName.Equals("@") || server.Session.SecondaryServerName.Equals("*") || server.Session.SecondaryServerName.Equals("CURRENT SCREEN") || server.Session.SecondaryServerName.Equals("CURRENT TRANSACTION")))
			{
				server.Session.SecondaryServerName = server.Session.PrimaryServerName;
			}
			server.Session.CurrentRemoteForm = setFieldsAction.ReadValuesFrom;
			if (server.Session.CurrentRemoteForm.StartsWith("$") && server.Session.CurrentRemoteForm.EndsWith("$"))
			{
				server.Session.CurrentRemoteForm = setFieldsAction.SampleForm;
			}
			if (server.Session.CurrentRemoteForm != null && (server.Session.CurrentRemoteForm.Equals("@") || server.Session.CurrentRemoteForm.Equals("*") || server.Session.CurrentRemoteForm.Equals("CURRENT SCREEN") || server.Session.CurrentRemoteForm.Equals("CURRENT TRANSACTION")))
			{
				server.Session.CurrentRemoteForm = server.Session.CurrentLocalForm;
			}
			array[0] = Util.ConvertToARFieldAssignmentList(setFieldsAction.FieldAssignments, server.Session.GetServer(server.Session.SecondaryServerName), server.Session.CurrentLocalForm, server.Session.CurrentRemoteForm, setFieldsAction.IsAssignmentsByMatchingIds, setFieldsAction.IsAssignmentSetToDefaults);
			array[1] = ARTypeMgr.Instance.toVariant(setFieldsAction.SampleServer);
			array[2] = ARTypeMgr.Instance.toVariant(setFieldsAction.SampleForm);
			if (!(setFieldsAction is SetFieldsFromCurrent))
			{
				if (setFieldsAction is SetFieldsFromFilterAPI)
				{
					string serviceName = ((SetFieldsFromFilterAPI)setFieldsAction).ServiceName;
					SetFieldsAction.FixARAssignFieldStruct("ARFieldAssignList", (object[])array[0], "", "", null, "", serviceName, 3u, 6u);
					object obj = Util.ConvertToARAssignmentList(((SetFieldsFromFilterAPI)setFieldsAction).InputValues, server.Session.GetServer(server.Session.SecondaryServerName), "User", 8u, server.Session.CurrentRemoteForm);
					((object[])((object[])((object[])((object[])array[0])[0])[1])[1])[1] = obj;
				}
				else
				{
					if (setFieldsAction is SetFieldsFromForm)
					{
						string serverName = "@";
						string arg_30B_0 = (server.Session.CurrentObjectType == Server.ObjectType.ActiveLink) ? "*" : "@";
						if (string.Compare(server.ServerName, server.Session.SecondaryServerName, true) != 0)
						{
							serverName = server.Session.SecondaryServerName;
						}
						string currentRemoteForm = server.Session.CurrentRemoteForm;
						object qualifier = server.ParseSetIfQualification(server.Session.CurrentRemoteForm, server.Session.CurrentLocalForm, ((SetFieldsFromForm)setFieldsAction).SetIfQualification);
						SetFieldsAction.FixARAssignFieldStruct("ARFieldAssignList", (object[])array[0], serverName, currentRemoteForm, qualifier, "", "", ((SetFieldsFromForm)setFieldsAction).NoMatchOption, ((SetFieldsFromForm)setFieldsAction).MultiMatchOption);
					}
					else
					{
						if (setFieldsAction is SetFieldsFromSQL)
						{
							string serverName2 = "@";
							string sqlCommand = ((SetFieldsFromSQL)setFieldsAction).SqlCommand;
							SetFieldsAction.FixARAssignFieldStruct("ARFieldAssignList", (object[])array[0], serverName2, "", "", sqlCommand, "", ((SetFieldsFromSQL)setFieldsAction).NoMatchOption, ((SetFieldsFromSQL)setFieldsAction).MultiMatchOption);
						}
					}
				}
			}
			return array;
		}
		private static object[] GetFirstARAssignFieldStruct(string holderTypStr, object[] rawData)
		{
			if (holderTypStr.Equals("ARFieldAssignStruct"))
			{
				return SetFieldsAction.GetFirstARAssignFieldStruct("ARAssignStruct", (object[])Util.GetAt(rawData, new int[]
				{
					1
				}));
			}
			if (holderTypStr.Equals("ARAssignStruct"))
			{
				int[] indexSpec = new int[1];
				switch (Convert.ToUInt32(Util.GetAt(rawData, indexSpec)))
				{
				case 2u:
					return rawData;
				case 4u:
					return SetFieldsAction.GetFirstARAssignFieldStruct("ARArithOpAssignStruct", (object[])Util.GetAt(rawData, new int[]
					{
						1
					}));
				case 5u:
					return SetFieldsAction.GetFirstARAssignFieldStruct("ARFunctionAssignStruct", (object[])Util.GetAt(rawData, new int[]
					{
						1
					}));
				case 7u:
					return rawData;
				case 8u:
					return rawData;
				}
			}
			else
			{
				if (holderTypStr.Equals("ARFieldAssignStruct"))
				{
					return SetFieldsAction.GetFirstARAssignFieldStruct("ARAssignStruct", (object[])Util.GetAt(rawData, new int[]
					{
						1
					}));
				}
				if (holderTypStr.Equals("ARArithOpAssignStruct"))
				{
					object[] firstARAssignFieldStruct = SetFieldsAction.GetFirstARAssignFieldStruct("ARAssignStruct", (object[])Util.GetAt(rawData, new int[]
					{
						2
					}));
					int[] indexSpec = new int[1];
					uint num = Convert.ToUInt32(Util.GetAt(rawData, indexSpec));
					if (firstARAssignFieldStruct == null && num != 6u)
					{
						firstARAssignFieldStruct = SetFieldsAction.GetFirstARAssignFieldStruct("ARAssignStruct", (object[])Util.GetAt(rawData, new int[]
						{
							1
						}));
					}
					return firstARAssignFieldStruct;
				}
				if (holderTypStr.Equals("ARFunctionAssignStruct"))
				{
					object[] array = (object[])Util.GetAt(rawData, new int[]
					{
						1
					});
					object[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						object obj = array2[i];
						object[] firstARAssignFieldStruct2 = SetFieldsAction.GetFirstARAssignFieldStruct("ARAssignStruct", (object[])obj);
						if (firstARAssignFieldStruct2 != null)
						{
							object[] result = firstARAssignFieldStruct2;
							return result;
						}
					}
					goto IL_22E;
				}
				if (holderTypStr.Equals("ARFieldAssignList"))
				{
					for (int i = 0; i < rawData.Length; i++)
					{
						object obj2 = rawData[i];
						object[] firstARAssignFieldStruct3 = SetFieldsAction.GetFirstARAssignFieldStruct("ARFieldAssignStruct", (object[])obj2);
						if (firstARAssignFieldStruct3 != null)
						{
							object[] result = firstARAssignFieldStruct3;
							return result;
						}
					}
				}
			}
			IL_22E:
			return null;
		}
		private static void FixARAssignFieldStruct(string holderTypStr, object[] rawData, string serverName, string formName, object qualifier, string sqlCommand, string serviceName, uint noMatchOption, uint multiMatchOption)
		{
			if (holderTypStr.Equals("ARFieldAssignStruct"))
			{
				object[] rawData2 = (object[])Util.GetAt(rawData, new int[]
				{
					1
				});
				SetFieldsAction.FixARAssignFieldStruct("ARAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
				return;
			}
			if (holderTypStr.Equals("ARAssignStruct"))
			{
				int[] indexSpec = new int[1];
				switch (Convert.ToUInt32(Util.GetAt(rawData, indexSpec)))
				{
				case 0u:
				case 1u:
				case 3u:
				case 6u:
					break;
				case 2u:
					((object[])rawData[1])[0] = serverName;
					((object[])rawData[1])[1] = formName;
					((object[])rawData[1])[2] = qualifier;
					((object[])rawData[1])[5] = noMatchOption;
					((object[])rawData[1])[6] = multiMatchOption;
					return;
				case 4u:
				{
					object[] rawData2 = (object[])Util.GetAt(rawData, new int[]
					{
						1
					});
					SetFieldsAction.FixARAssignFieldStruct("ARArithOpAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					return;
				}
				case 5u:
				{
					object[] rawData2 = (object[])Util.GetAt(rawData, new int[]
					{
						1
					});
					SetFieldsAction.FixARAssignFieldStruct("ARFunctionAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					return;
				}
				case 7u:
					((object[])rawData[1])[0] = serverName;
					((object[])rawData[1])[1] = sqlCommand;
					((object[])rawData[1])[3] = noMatchOption;
					((object[])rawData[1])[4] = multiMatchOption;
					return;
				case 8u:
					((object[])rawData[1])[0] = serviceName;
					return;
				default:
					return;
				}
			}
			else
			{
				if (holderTypStr.Equals("ARFieldAssignStruct"))
				{
					object[] rawData2 = (object[])Util.GetAt(rawData, new int[]
					{
						1
					});
					SetFieldsAction.FixARAssignFieldStruct("ARAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					return;
				}
				if (holderTypStr.Equals("ARArithOpAssignStruct"))
				{
					object[] rawData2 = (object[])Util.GetAt(rawData, new int[]
					{
						2
					});
					SetFieldsAction.FixARAssignFieldStruct("ARAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					int[] indexSpec = new int[1];
					uint num = Convert.ToUInt32(Util.GetAt(rawData, indexSpec));
					rawData2 = (object[])Util.GetAt(rawData, new int[]
					{
						1
					});
					if (num != 6u)
					{
						SetFieldsAction.FixARAssignFieldStruct("ARAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					}
					return;
				}
				if (holderTypStr.Equals("ARFunctionAssignStruct"))
				{
					object[] array = (object[])Util.GetAt(rawData, new int[]
					{
						1
					});
					object[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						object obj = array2[i];
						object[] rawData2 = (object[])obj;
						SetFieldsAction.FixARAssignFieldStruct("ARAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					}
					return;
				}
				if (holderTypStr.Equals("ARFieldAssignList"))
				{
					for (int i = 0; i < rawData.Length; i++)
					{
						object obj2 = rawData[i];
						object[] rawData2 = (object[])obj2;
						SetFieldsAction.FixARAssignFieldStruct("ARFieldAssignStruct", rawData2, serverName, formName, qualifier, sqlCommand, serviceName, noMatchOption, multiMatchOption);
					}
				}
			}
		}
	}
}
